<template>
  <div class="movie_body">
    <loading v-if="isLoading"></loading>
    <scroll v-else :handleToScroll='handleToScroll' :handleToTouchEnd='handleToTouchEnd'>
      <ul>
        <li v-if="pullDownMsg">{{pullDownMsg}}</li>
        <li v-for="item in movieList" :key="item.id">
          <div class="pic_show" @tap="handleToDetail(item.id)">
            <img :src="item.img | setWH('128.180')" alt="">
          </div>
          <div class="info_list">
            <h2 @tap="handleToDetail(item.id)">{{item.nm}}<img v-if="item.version" src="@/assets/3dmax.png" alt=""></h2>
            <p>观众评 <span class="grade">{{item.sc}}</span></p>
            <p>{{item.star}}</p>
            <p>{{item.showInfo}}</p>
          </div>
          <div class="btn_mall">
            购票
          </div>
        </li>
      </ul>
    </scroll>
  </div>
</template>

<script>
import Bscroll from 'better-scroll'
export default {
  data() {
    return{
      movieList: [],
      pullDownMsg: '',
      isLoading: true,
      prevCity: -1
    }
  },
  methods:{
    handleToDetail(movieId) {
     this.$router.push(`/movie/nowing/detail/${movieId}`)
    },
    async fetch() {
      let cityId = this.$store.state.city.id
      if(cityId === this.prevCity ) { return }
      this.isLoading = true
      const res = await this.$axios.get(`/api/movieOnInfoList?cityId=${cityId}`)
      this.movieList = res.data.data.movieList
      this.isLoading = false
      this.prevCity = cityId
    },
    handleToScroll(pos) {
      if(pos.y > 30) {
        this.pullDownMsg = '正在更新'
      }
    },
    handleToTouchEnd(pos) {
      this.$axios.get(`/api/movieOnInfoList?cityId=${this.prevCity}`)
      .then(res => {
        this.movieList = res.data.data.movieList
        this.pullDownMsg = '更新成功'
        this.pullDownMsg = ''
      })
      .catch(err=> console.log(err))
    }
  },
  activated() {
    this.fetch()
  },
}
</script>

<style scoped>
#content .movie_body{ overflow:auto; flex:1;}
.movie_body ul{ margin:0 12px; overflow: hidden;}
.movie_body ul li{ margin-top:12px; display: flex; align-items:center; border-bottom: 1px #e6e6e6 solid; padding-bottom: 10px;}
.movie_body .pic_show{ width:64px; height: 90px;}
.movie_body .pic_show img{ width:100%;}
.movie_body .info_list { margin-left: 10px; flex:1; position: relative;}
.movie_body .info_list h2{ font-size: 17px; line-height: 24px; width:150px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis;}
.movie_body .info_list p{ font-size: 13px; color:#666; line-height: 22px; width:200px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis;}
.movie_body .info_list .grade{ font-weight: 700; color: #faaf00; font-size: 15px;}
.movie_body .info_list img{ width:50px; position: absolute; right:10px; top: 5px;}
.movie_body .btn_mall , .movie_body .btn_pre{ width:47px; height:27px; line-height: 28px; text-align: center; background-color: #f03d37; color: #fff; border-radius: 4px; font-size: 12px; cursor: pointer;}
.movie_body .btn_pre{ background-color: #3c9fe6;}
</style>
